#include "uart.h"

#define UART_BASE 0x10000000
#define UART_THR 0x00
#define UART_LSR 0x05
#define UART_LSR_THRE 0x20

void uart_putc(char c) {
    volatile uint8_t *thr = (uint8_t *)(UART_BASE + UART_THR);
    volatile uint8_t *lsr = (uint8_t *)(UART_BASE + UART_LSR);

    // 等待发送保持寄存器为空，即可以发送数据
    while ((*lsr & UART_LSR_THRE) == 0)
        ;
    // 向发送保持寄存器写入字符
    *thr = c;
}

void uart_puts(const char *s) {
    // 依次发送字符串中的每个字符
    while (*s) {
        uart_putc(*s++);
    }
}
